package cn.webrx;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Stream5 {
    public static void main(String[] args) {
        //建立对象集合
        List<Book> books = new ArrayList<>(List.of(
                new Book(1, "《java基础入门》", "李四", 38),
                new Book(20, "《html基础》", "王四", 28),
                new Book(15, "《企业java项目初步》", "赵四", 18),
                new Book(33, "《mysql》", "张四", 88),
                new Book(33, "《mysql》", "张四", 88),
                new Book(9, "《数据库视频》", "李四", 55)));

        Stream<Book> stream = books.stream();

        //IntStream is = stream.mapToInt(e -> e.getId());
        //is.forEach(System.out::println);

        //Stream<String> ss = stream.map(e->e.getName());
        //ss.forEach(System.out::println);

        //Stream<Book> 转 List<Book>
        //List<Book> mlist = stream.collect(Collectors.toList());
        //mlist.add(new Book(22,"《html5》","李强",32));
        //for (Book book : mlist) {
        //    System.out.println(book);
        //}

        //Set<String> set = stream.map(Book::getAuthor).collect(Collectors.toSet());
        //System.out.println(set);

        System.out.println(stream.map(Book::getAuthor).collect(Collectors.joining(",")));

    }
}
